<template>
    <div>
      <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="user_id"
        label="用户ID"
        width="180">
      </el-table-column>
      <el-table-column
        prop="user_name"
        label="用户姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="user_password"
        label="用户密码">
      </el-table-column>
      <el-table-column
        prop="user_phone"
        label="用户手机">
      </el-table-column>
      <el-table-column
        prop="user_email"
        label="用户邮箱">
      </el-table-column>
       <el-table-column
            fixed="right"
            label="操作"
            width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.$index,tableData)" type="text" size="small">删除</el-button>
        <el-button type="text" size="small" @click="editUser(scope.row)">编辑</el-button>
      </template>
    </el-table-column>
    </el-table>
    </div>
</template>
<script>
export default {
    data(){
        return{
            tableData:this.$store.state.managUser
        }
    },
    methods:{
        handleClick(index,rows){
            let userInfo = {
                'user_id':rows[index].user_id
            };
            this.axios.post("/api/shopping/deleteUser.php",userInfo).then(res=>{
                if(res.data=="ok"){
                    this.tableData.splice(index,1);
                    this.$message({
                        type:'success',
                        message:'删除成功'
                    });
                }else{
                    this.$message({
                        type:'success',
                        message:'删除失败'
                    });
                }
            });
        },
        editUser(row){
            this.$router.push({path:'/editUser',params:{
                'user_id':row.user_id,
                'user_name':row.user_name,
                'user_password':row.user_password,
                'user_phone':row.user_phone,
                'user_email':row.user_email 
                }});
        }
    }
}
</script>